package com.foreknow.test;

public class Manager {
    private Employee[] emps;
    private int count;
    public Manager(){
        emps = new Employee[5];
    }
    //添加员工信息
    public  void save(Employee emp){
        //1.判断emp是否为空
        if (emp != null){
            //2.如果emp不为空还要判断添加的元素不能超出数组的长度
            if (count < 5){
                //3.要将emp保存到emps数组中并输出是否添加成功
                emps[count] = emp;
                count++;
                System.out.println("添加成功.....");
            }else {
                System.out.println("添加失败.....");
            }
        }
    }
    public Employee getQueryById(String id){
        Employee employee = null;
        for (int i = 0 ;i < emps.length;i++){
            if (id.equals(emps[i].getEid())){
                employee = emps[i];
                break;
            }
        }
        return employee;
    }
    public Employee update(Employee employee){
        employee.setName("xxx");
        return employee;
    }


    public static void main(String[] args) {
        Manager manager = new Manager();
        Employee e1 = new Employee();
        e1.setEid("10000");
        e1.setName("fender1");
        Employee e2 = new Employee();
        e2.setEid("10001");
        e2.setName("fender2");
        Employee e3 = new Employee();
        e3.setEid("10002");
        e3.setName("fender3");
        Employee e4 = new Employee();
        e4.setEid("10003");
        e4.setName("fender4");
        Employee e5 = new Employee();
        e5.setEid("10004");
        e5.setName("fender5");
        manager.save(e1);
        manager.save(e2);
        manager.save(e3);
        manager.save(e4);
        manager.save(e5);

        //调用根据id查询
        Employee em = manager.getQueryById("10002");
        System.out.println(em.getEid()+"-----"+em.getName());

        //update修改
        Employee employee = manager.update(em);
        System.out.println(employee.getEid()+"----"+employee.getName());

    }
}
